package com.penghaisoft.microwms.material.web.outwarehouse.controller;

import java.util.Date;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.data.model.RawRequisition;
import com.penghaisoft.microwms.common.data.model.RawRequisitionSn;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.material.web.outwarehouse.service.OutWhRawService;

/**
 * Created by 王治国 on 2018/5/17.
 * 原材料出库查询
 */
@RestController
@RequestMapping(value = "raw/rawOutWh")
@Slf4j
public class OutWhRawController extends BaseController {

    @Autowired
    private OutWhRawService outWhRawService;

    @PostMapping("list")
    public TransResult findAll(@RequestParam(name = "page", defaultValue = "1") int page,
                               @RequestParam(name = "rows", defaultValue = "10") int rows, RawRequisition rawRequisition) {
        Pager<RawRequisition> result = outWhRawService.findAll(page, rows, rawRequisition);
        return success(result);
    }
    
    /** 
     * @Title findList
     * @Description 根据领料单号查询数据
     * @author luoteng
     * @date 2018年7月3日:下午4:32:02
     * @param rawRequisition
     * @return TransResult
     */
    @PostMapping("list/info")
    public TransResult findList(RawRequisition rawRequisition) {
    	TransResult result = new TransResult();
    	result.setCode(Constant.SUCCESS);
    	rawRequisition.setActiveFlag("1");
        List<RawRequisition> list = outWhRawService.findList(rawRequisition);
        if(list != null && !list.isEmpty()){
        	RawRequisition tmp = list.get(0);
        	tmp.setCreateBy(getUserName());
        	tmp.setGmtCreate(new Date());
        }
        result.setList(list);
        return result;
    }
    
    /** 
     * @Title findListByRequestionNo
     * @Description 根据领料单号查询列表
     * @author luoteng
     * @date 2018年7月3日:下午4:32:02
     * @param page
     * @param rows
     * @param rawRequisitionSn
     * @return TransResult
     */
    @PostMapping("list/requisitionNo")
    public TransResult findListByRequestionNo(@RequestParam(name = "page", defaultValue = "1") int page,
                               @RequestParam(name = "rows", defaultValue = "10") int rows, RawRequisitionSn rawRequisitionSn) {
    	rawRequisitionSn.setActiveFlag("1");
        Pager<RawRequisitionSn> result = outWhRawService.findListByRequestionNo(page, rows, rawRequisitionSn);
        return success(result);
    }

}
